<template>
  <van-nav-bar
      title="重置密码"
      style="width: 400px"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
  />
  <van-cell-group inset >
    <van-field v-model="user.password" type="password" label="请输入新密码    " />
    <van-field v-model="user.password" type="text" label="请再次输入" />
    <van-button type="primary" @click="onClickRight">确认</van-button>
  </van-cell-group>
</template>

<script setup>
import {useRouter} from "vue-router";
const router = useRouter();
import {ref} from "vue";
import {showToast} from "vant";
import {post} from "../../util/request.js";
const onClickLeft = () => {
  router.push("/accountSecurity");
  // 返回按钮逻辑
};
const user = ref({
  password: "",
});
const onClickRight = () => {
  post(
   'user/updatePassword',{
    password: user.value.password}
  ).then(
      (data) => {
        if (data.code == 0) {
          showToast("修改成功");
          user.value = data.data;// 初始化界面
         alert("修改成功，请重新登录")
          router.push("/login");
        } else {
          showToast(data.msg);
        }
      })
      .catch(
          function () {
            alert("服务器错误")
          }
      )
};
</script>

<style scoped>

</style>